package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.DNSBackupServerAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;

/**
 * @ClassName : DNSBackupServerAttrLinkHandler
 * @Description :
 * @Author : xie.zhengjun
 * @Date : 2020/12/16 18:05
 */
@Service
@AttrHandler(DNSBackupServerAttrHandler.class)
public class DNSBackupServerAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        if (KiteStringUtils.isEqual("sceneTempl", KiteMapUtils.getString(data.getExtAttributes(), "entry"))) {
            return;
        }
        String masterServerVal = inst.getAttrValue("200004015");

        if (KiteStringUtils.isNotEmpty(attr.getValue()) && KiteStringUtils.isEqual(attr.getValue(), masterServerVal)) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut("DNS服务器（主）和DNS服务器（备）不能相同");
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
